<?=$header?>

<script src="<?=base_url();?>system/scriptaculous/lib/prototype.js" type="text/javascript"></script>
<script src="<?=base_url();?>system/scriptaculous/src/scriptaculous.js" type="text/javascript"></script>
<script src="<?=base_url();?>system/scriptaculous/src/unittest.js" type="text/javascript"></script>

<script type="text/javascript">
function submitOrder(){
	var params = Sortable.serialize('menu_list');
	new Ajax.Request('<?=base_url();?>ajax/orderMenu', {
	method:'post',
	asynchronous:true, 
	parameters:params,
	onLoading: function(){
		$("updateDiv").style.display = '';
		$("updateDiv").innerHTML = 'Saving...';
	},
	onSuccess: function(transport){
		var response = transport.responseText || "no response text";
		//alert("Success! \n" + response);
		$("updateDiv").innerHTML = 'Saved';
	},
	onFailure: function(){ 
		$("updateDiv").innerHTML = 'Failed to save';
	}
	});
	
	var params = Sortable.serialize('other_list');
	new Ajax.Request('<?=base_url();?>ajax/orderOther', {
	method:'post',
	asynchronous:true, 
	parameters:params,
	onLoading: function(){
		$("updateDiv").style.display = '';
		$("updateDiv").innerHTML = '<img src="<?=base_url();?>system/images/loader.gif" alt="" /> Saving...';
	},
	onSuccess: function(transport){
		var response = transport.responseText || "no response text";
		//alert("Success! \n" + response);
		$("updateDiv").style.display = 'none';
	},
	onFailure: function(){ 
		$("updateDiv").innerHTML = 'Failed to save <a href="#" onclick="closeDiv();">close</a>';
	}
	});
}

function closeDiv(){
	$("updateDiv").style.display = 'none';
}
</script>

<p>Create a <? echo anchor('manage/create', 'new page'); ?> or select a page to edit:<br />
<? 
$this->Manage_Model->get_entries();
?>
</p>

<script type="text/javascript" language="javascript" charset="utf-8">
// <![CDATA[
  Sortable.create('menu_list',{containment:['menu_list','other_list'], dropOnEmpty:true, onUpdate: submitOrder });
  Sortable.create('other_list',{containment:['menu_list','other_list'], dropOnEmpty:true, onUpdate: submitOrder });
// ]]>
</script>

<p><div id="updateDiv" style="display:none;border:1px dotted #ccc;padding:5px;"></div></p>

<?=$footer?>

</body>
</html>